package ModelLayer;

import java.util.ArrayList;

/**
 * Write a description of class DVD here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    // instance variables - replace the example below with your own
    private int id;
    private String title;
    private String artist;
    private double releaseDate;
    private ArrayList<Copy> copy;
    
    public DVD(int id, String title, String artist, double releaseDate)
    {
        copy = new ArrayList<Copy>();
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.releaseDate = releaseDate;
    }
    
    public void setID(int id)
    {
        this.id = id;
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public void setArtist(String artist)
    {
        this.artist = artist;
    }
    
    public void setReleaseDate(double releaseDate)
    {
        this.releaseDate = releaseDate;
    }
    
    public int getID()
    {
        return id;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public String getArtist()
    {
        return artist;
    }
    
    public double getReleaseDate()
    {
        return releaseDate;
    }
    
    public void addCopy(int id, int serialNr, double purchaseDate, double purchasePrice)
    {
        Copy c = new Copy(serialNr, purchaseDate, purchasePrice);
        copy.add(c);
    }
    
    public void deleteCopy(Copy c)
    {
        copy.remove(c);
    }
    
    public Copy getCopy(int serialNr)
    {
        int index = 0;
        Copy c = null;
        boolean found = false;
        
        while(index < copy.size() && !found)
        {
            c = copy.get(index);
            
            if(c.getSerialNr() == serialNr)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        if(found)
        {
            return copy.get(index);
        }
        else
        {
            return null;
        }
    }
    
    public ArrayList getArrayList()
    {
        return copy;
    }
    
    public Copy getCopyIndex(int index)
    {
        return copy.get(index);
    }
}
